package cn.wolfcode.domain;

import cn.wolfcode.meiju.AppointmentStatusEnum;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Appointment {
    private Long id;

    private String ano;

    private Integer status;

    private SystemDictionaryItem systemDictionaryItem;

    private String info;

    private String contactTel;

    private String contactName;

    private Business business;
    @DateTimeFormat(pattern = "yyyy-MM-dd mm:ss")
    private Date createTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd mm:ss")
    private Date appointmentTime;

    //由于页面回显，我们需要根据对应的数值，换成对应的状态字符串
    //根据自己的状态值，找到对应的状态名称（拿到枚举类进行比对）
    public String getStatusName(){
        return AppointmentStatusEnum.getStatusByValue(status);
    }

    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        if (business!=null){

            map.put("businessId",business.getId());
        }
        map.put("id",id);
        if (systemDictionaryItem!=null){
            map.put("sdi_id",systemDictionaryItem.getId());

        }
        map.put("appointmentTime",new SimpleDateFormat("yyyy-MM-dd mm:ss").format(appointmentTime));
        if (systemDictionaryItem!=null){

            map.put("ItemName",systemDictionaryItem.getTitle());
        }
        map.put("contactName",contactName);
        map.put("contactTel",contactTel);
        map.put("info",info);
        map.put("a",1);
        System.out.println(JSON.toJSONString(map));
        return JSON.toJSONString(map);
    }

}